/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-03-29
 * Time: 19:06
 */
class Count {
    public int count;
    public void add(){
        count++;
    }
    public int get(){
        return count;
    }
}
public class Demo1 {
    public static void main(String[] args) throws InterruptedException {
        Count count=new Count();
        Thread t1=new Thread(()->{
            for (int i = 0; i <50000 ; i++) {
                synchronized (count){
                    count.add();
                }

            }
        });
        Thread t2=new Thread(()->{
            for (int i = 0; i <50000 ; i++) {
                synchronized (count){
                    count.add();
                }

            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println("count= " +count.get());

    }
}
